<?php

	$categoryId = isset($_GET['id']) ? $_GET['id'] : '';
	$goodId = isset($_GET['good']) ? $_GET['good'] : '';

	$db = mysql_connect('localhost','root','') or die('connect failed');
	mysql_select_db('buhlo') or die('not select db');
	mysql_set_charset('UTF8');

	if ($categoryId) {

		$category = mysql_query('SELECT * FROM `goods` WHERE id_category = ' . $categoryId, $db);

	} elseif ($goodId) {
		print($goodId);
		$goods = mysql_query('SELECT * FROM `goods` WHERE id = ' . $goodId, $db);

	}

	$categories = mysql_query('SELECT * FROM `categories`', $db);

	mysql_close($db);

?><!DOCTYPE html>
<html lang="ru">
<head>
	<meta charset="UTF-8">
	<title>Test DB</title>
</head>
<body>
	<?
	
	
	while ($category = mysql_fetch_assoc($categories)){
		print('<li><a href="index.php?id='. $category['id'] .'">'. $category['name'] .'</a></li>');
	}
	
	if($goodId){
		print($goodId);
	}

	if($goodId){
		while ($good = mysql_fetch_assoc($goods)){
			print('<table>');
			print('	<tr>');
			print('		<td><img src="' . $good['image'] . '"></td>');
			print('	</tr>');
			print('	<tr>');
			print('		<td>');
			print('			<h3><a href="index.php?good=">' . $good['name'] . '</a></h3>');
			print('			<p>' . $good['intro'] . '</p>');
			print('		</td>');
			print('	</tr>');
			print('	<tr>');
			print('		<td><h2>' . $good['cost'] . '</h2></td>');
			print('	</tr>');
			print('</table>');
		}
	}

	?>


</body>
</html>